Software Tools for Earth and Environmental Science - Week 2

YSB 801E

September 27, 2019

Linux and Python

  • Syllabus, Book and Last Week

  • Unix and Gnu/Linux

  • Terminal

  • Basic GNU/Linux Commands

  • Python and Jupyter

Syllabus, Book and Last Week

Syllabus

Extended Syllabus PDF

Book

The Book of R - PDF

Last Week

Course Home Page LINK

Week 1 - Presentation LINK

Unix

What is Unix?

  • UNIX is a computer operating system.
  • It was first developed in 1969 at Bell Labs.
  • In 1972, the Unix code was rewritten with the new C programming language.

(Dennis, Ken)

GNU

What is GNU?

  • A wildebeest (or gnu) is an animal. Lives in Africa.
  • GNU is the name of a computer operating system.
  • The GNU project was started by Richard Stallman in 1983.
  • GNU’s Not Unix!
  • Fully free to modify, share and publish.

GNU/Linux

What is Linux (or GNU/Linux) ?

  • Linux (or GNU/Linux) is a Unix-like operating system.
  • GNU did not have all the parts.
  • The kernel (GNU Hurd) is not yet completely built.
  • In 1991 Linus Torvalds began to work -> Linux kernel.

How is Unix different from Linux?

  • Linux does not use code from UNIX.

  • The idea and names of commands are similar.

GNU/Linux Distributions

Linux_Distribution_Timeline

Terminal

Terminal

A computer terminal is a hardware device that is used for entering data into, and displaying or printing data from a computer or a computing system.

Terminal

Basic GNU/Linux Commands

Basic GNU/Linux Commands

  • Frequently Used Terms

  • Directory Commands

  • File Commands

  • Special Commands

  • vi Editor, Print Commands and Symbols

Frequently Used Terms

Frequently Used Terms

  • File and Folder
  • Directory
    • Parent Directory
    • Working Directory
  • User
  • Root or Root Directory
  • Environments
  • Backup
  • Command, Command Line, Console
  • Warning, Error, Permission Denied
  • Segmentation Fault

Frequently Used Terms

  • File and Folder
  • Directory Path, Parent and Working Directory

Frequently Used Terms

User, Root and Home Directory

whoami
## emirtoker

Root directory symbol; “/”. Home directory symbol; “~”.

Frequently Used Terms

Environments and Backup

printenv  

Frequently Used Terms

Command Line, Command

Frequently Used Terms

Warning, Error, Permission Denied, Segmentation Fault

Directory Commands

Directory Commands

  • pwd (Print Working Directory)

  • ls (List Directories)

  • cd (Change Directory)

  • mkdir (Make Directory)

Directory Commands - pwd

(Print Working Directory)

pwd
## /Users/emirtoker/Desktop/Dersler/Memurluk/Software_Tools_for_Earth_&_Environmental_Science/Software_Tools_R_Github/Presentation

Directory Commands - ls

(List Directories)

ls
## Presentation.Rproj
## Presentation_Week1_-_Data_and_Code.Rmd
## Presentation_Week1_-_Data_and_Code.html
## Presentation_Week2_-_Linux_and_Python.Rmd
## Presentation_Week2_-_Linux_and_Python.html
## Presentation_Week2_-_Linux_and_Python.pdf
## Richard.jpg
## Software_Tools_for_Earth_and_Environmental_Science_Syllabus.png
## The_Book_of_R.png
## Week1_rpubs.Rmd
## Week1_rpubs.html
## ai.png
## algorithm.png
## alma.jpg
## anaconda.png
## analysis.png
## apache_point.jpg
## arcgis.png
## big_data1.png
## book_flow.png
## cd1.png
## cd2.png
## clear.png
## code.png
## command_line.png
## conda.png
## course_github.png
## coursera.png
## cp.png
## cp1.png
## cygwin.png
## data_analytics.png
## data_assim.jpeg
## data_mining.svg
## datacamp.png
## datascience.png
## datashape.jpg
## datum.png
## deep.jpg
## download.png
## dropbox.png
## earthdata.png
## eda.png
## edx.png
## exit.png
## extended_syllabus.png
## extended_syllabus1.png
## filer_folder.png
## filezilla.png
## find.png
## generate.png
## github.png
## gnu_logo.png
## help.png
## history.png
## iot.png
## jupyter.png
## jupyter_notebook.png
## kernel.jpg
## khanacademy.png
## languages.png
## last_week.png
## linus.jpeg
## linux_dist.png
## linux_logo.png
## machine.jpg
## mendeley.png
## metadata0.png
## metadata1.png
## meted.png
## mining.jpg
## mining1.jpg
## mkdir1.png
## mkdir2.png
## model.png
## mv.png
## my_profile
## mynewfile.png
## nc.png
## ncl.png
## orcid.png
## os.png
## overleaf.png
## panoply.png
## printenv.png
## pwd_mac.png
## pwd_mac1.png
## pwd_win.png
## python.jpg
## python_term.png
## qgis.png
## researchgate.png
## rm.png
## root.png
## root_fig.gif
## rsconnect
## rstudio.png
## simulation.jpg
## stackoverflow.png
## sublimetext.png
## syllabus.png
## terminal.png
## terminal0.png
## terminal1.png
## touch.png
## udemy.png
## unix_develop.jpg
## unix_linux.png
## vi_0.png
## vi_1.png
## vi_2.png
## vi_3.png
## visual.jpg
## warning.png
## wetransfer.png
## wget.jpg
## what_data.svg
## win_folder.png
## wolfram-alpha.png
## zenodo-doi.png

Directory Commands - pwd and ls

Directory Commands - cd

(Change Directory)

cd Presentation/

Directory Commands - mkdir

(Make Directory)

mkdir <new_folder_name>

File Commands

File Commands

  • touch

  • cat (Concatenate)

  • rm (Remove)

  • cp (Copy)

  • mv (Move)

File Commands - touch

touch <my_new_file>

File Commands - cat

(Concatenate)

cat my_new_file
This is my new file. Hi!

File Commands - cp

(Copy)

cp my_new_file my_new_file2

File Commands - mv

(Move)

mv my_new_file2 my_new_file3

File Commands - rm

(Remove)

rm my_new_file my_new_file3

Special Commands

Special Commands

  • find

  • help

  • history

  • clear

  • date and cal

  • exit

Special Commands - find

find -name <name_of_file>

Special Commands - help

find --help

Special Commands - history

history

Special Commands - clear

clear

Special Commands - date and cal

date
## Mon Sep 30 15:55:20 +03 2019
cal
##    September 2019     
## Su Mo Tu We Th Fr Sa  
##  1  2  3  4  5  6  7  
##  8  9 10 11 12 13 14  
## 15 16 17 18 19 20 21  
## 22 23 24 25 26 27 28  
## 29 _3_0                 
## 

Special Commands - exit

exit

vi Editor

vi Editor and Print Commands

  • vi

  • esc (default mode)

  • i (insert mode)

  • :q (just quit)

  • :q! (don’t save and quit)

  • :qw (write/save and quit)

  • grep and echo

  • head and tail

  • sed (stream editor)

vi Editor and Print Commands - vi

vi Editor and Print Commands - esc

(Default Mode)

vi Editor and Print Commands - i

(Insert Mode)

vi Editor and Print Commands - :wq

(Write/Save and Quit)

vi Editor and Print Commands - grep and echo

grep my_profile
grep ITU my_profile
echo my_profile
name=Emir
echo $name

vi Editor and Print Commands - head and tail

head my_profile
tail my_profile

vi Editor and Print Commands - sed

(Stream Editor)

Replacing or substituting string;

sed 's/ITU/ODTU/' my_profile
sed '5d' my_profile 

Symbols

Symbols

  • | (and)
  • > (assing)
  • $ (special variable)
  • ? (an unknown character)
  • * (an unknown sroup of characters)
cat my_profile | sort
ls > my_list
x=3
echo $x
ls my*
ls ?y_list* 

BONUS

Bash Script

touch my_bash_script.sh
vi my_bash_script.sh
x=5
y=3
echo $((x+y))
bash my_bash_script.sh
8

Practice and Quiz

Practice

  1. Learn where you are (Print your working directory)
  2. Look at inside (list all documents and directories)
  3. Create a new folder (make a directory,<my_new_dir>)
  4. Go to the <my_new_dir> (change your directory)
  5. Create a new file (touch it, file name : <my_new_file>)
  6. Open this new file and write your name (vi-insert mode)
  7. Save your work and close the file (write + quit)
  8. Print your name on the screen (grep, tail, head, cat)
  9. Put <my_new_file> at the parent directory (move it)
  10. Go to parent directory (change directory with two dots)
  11. Create a copy, name; <my_new_file_2>
  12. Remove your first folder <my_new_dir>
  13. List all documents and directories

Quiz

Introduction to Gnu/Linux

LINK

Python and Jupyter

What is the Python

  • Python is a programming language.
  • Created by Guido van Rossum and first released in 1991.
  • Python 2.0, released 2000, Python 3.0, released 2008.
  • Python 2.7, the last release in the 2.x series, was extended to 2020.

Python in Terminal

webminal.org

GCC : GNU Compiler Collection

What is the Anaconda/Jupyter

Python in Anaconda/Jupyter

jupyter notebook

Next Week